﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SeaBattle.Domain.Abstract;
using SeaBattle.Domain.Entities;
using SeaBattle.Domain.Abstract.Services;

namespace SeaBattle.Domain.Concrete
{
    public class FakePlayerRepository:IPlayerRepository
    {

        private static List<Player> players = new List<Player> { 
            new Player("Вася Пупкин", "vasya"){Id = 1},
            new Player("Александр Македонский", "alex"){Id = 2},
            new Player("Андрей Шевченко", "andrew"){Id = 3}

        };
        
        
        public Player CreateNewPlayer(string name, string login)
        {
            return new Player(name,login);
        }


        public void SavePlayer(Player player)
        {
            //var playerService = PlayerFactory.CreatePlayerService();
            if (!players.Contains(player))
            {
                players.Add(player);
            }

        }



        public IEnumerable<Player> GetAllPlayers()
        {
            return players.AsEnumerable();
        }


        public Player GetPlayer(string login)
        {
            var player = players.FirstOrDefault(x => x.Login == login);
            if (player == null)
            {
                throw new IndexOutOfRangeException("Player with login " + login + " doesn't exist!");
            }
            return player;
            
        }

        public Player GetPlayer(int id)
        {
            return players.FirstOrDefault(x => x.Id == id);
            
        }
    }
}
